<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
@if ($errors->any())
    <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif
<form action="/store" method="post">
    @csrf
    <input type="text" name="username" id="username" value="">
{{--    <input type="submit" id="btn" value="提交">--}}
    <input type="button" id="btn" value="提交">
</form>

</body>
</html>
<script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
<script>
    var _token = "{{csrf_token()}}"
    $("#btn").click(function () {
        var username = $("#username").val()
        console.log(_token)
        $.ajax({
            type: "POST",
            url:'/store',
            data: {username,_token},
            dataType:'json',
            success: function(res) {
                console.log(res);
                alert(res.msg);
            },
            error : function (msg) {
                console.log(msg)
            }
        });
    })
</script>
